package com.xbongbong.crm.help;

import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.parent.factory.TeamDataFactory;
import com.xbongbong.parent.interfaces.TeamStrategy;
import com.xbongbong.pro.detailtab.vo.team.TeamListBatchPermissionVO;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author 吴峰
 * @date 2022/07/14 11:00
 */
@Component
public class CrmTeamPermissionHelp {

    @Resource
    private TeamDataFactory teamDataFactory;

    /**
     * 获取业务列表中与团队有关的一些批量操作的权限
     *
     * @param formDataListDTO 列表实体
     * @param explains 列表表单解释
     *
     * @return
     */
    public TeamListBatchPermissionVO getTeamListBatchPermission(FormDataListDTO formDataListDTO, List<FieldAttrEntity> explains) throws XbbException {
        List<Integer> shouldFilterBusList = Arrays.asList(XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(), XbbRefTypeEnum.PREPAY_BALANCE.getCode());
        Integer distributorMark = formDataListDTO.getDistributorMark();
        TeamStrategy teamStrategy = teamDataFactory.getStrategy(formDataListDTO.getBusinessType(), formDataListDTO.getDistributorMark(), formDataListDTO.getSaasMark());
        if (Objects.equals(DistributorMarkEnum.DISTRIBUTOR.getCode(), distributorMark)
                || shouldFilterBusList.contains(formDataListDTO.getBusinessType()) || Objects.isNull(teamStrategy)) {
            return new TeamListBatchPermissionVO();
        }
        return teamStrategy.getTeamListBatchPermission(formDataListDTO, explains);
    }
}
